#pragma once
#include "RBTree.h"

namespace wzw
{
	template <class K, class V>
	class map
	{
		typedef pair<const K, V> value_type;

		struct KeyOfValue
		{
			const K& operator()(const value_type& data)
			{
				return data.first;
			}
		};
	public:
		typedef typename RBTree<value_type, KeyOfValue>::iterator iterator;

		iterator begin()
		{
			return _t.begin();
		}
		iterator end()
		{
			return _t.end();
		}
		iterator begin() const
		{
			return _t.begin();
		}
		iterator end() const
		{
			return _t.end();
		}
	public:
		pair<iterator, bool> insert(const value_type& data)
		{
			return _t.Insert(data);
		}
		V& operator[](const K& key)
		{
			pair<iterator, bool> ret = _t.Insert(make_pair(key, V()));

			return ret.first->second;
		}
	private:
		RBTree<value_type, KeyOfValue> _t;
	};
}